home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / dfutil2.zip / CLEANER.ZIP / CLEANER.BAS next >
BASIC Source File  |  1990-11-10  |  3KB  |  108 lines

  1. 'CLEANER cleans upper ASCII and NULLS from files
  2. '
  3. ' $INCLUDE: 'qb.bi'
  4.  
  5. DECLARE FUNCTION exists (filename$)
  6.  
  7. DIM SHARED inregs AS RegTypeX, outregs AS RegTypeX
  8. CONST YES = 1, NO = 0
  9.   
  10.     CLS
  11.     infile$ = COMMAND$
  12.     IF infile$ = "" THEN GOTO help
  13.     OPEN infile$ FOR BINARY AS #1
  14.     q = LOF(1)
  15.     IF q = 0 THEN GOTO nofind
  16.     outfile$ = "temp"
  17.     OPEN outfile$ FOR OUTPUT AS #2
  18.     GOSUB filename
  19.     oldfile$ = file$ + ".OLD"
  20.     IF exists(oldfile$) = YES THEN KILL oldfile$
  21. HEADER:
  22.     COLOR 15: PRINT "CLEANER "; : COLOR 7: PRINT "Fast non-ASCII, upper ASCII and NULL cleaner"
  23.     PRINT "Cleaning "; infile$; "; making backup named "; file$; ".OLD"
  24.     PRINT "Hit [Ctrl]+[Break] to terminate."
  25.     GOSUB TIME
  26.     time1 = TIMER
  27.     PRINT " Start time  :"; newtime$
  28.     PRINT " Total bytes :"; q
  29.     PRINT " Est @130 bps:"; FIX(q / 130); "secs. "
  30.     z = 0: x = 0: y = 0
  31.     inline$ = INPUT$(q, #1)
  32.     DO
  33.         z = z + 1
  34.         IF z = q + 1 THEN EXIT DO
  35.         b$ = MID$(inline$, z, 1)
  36.         b = ASC(b$)
  37.         IF b = 9 OR (b > 31 AND b < 127) OR b = 10 OR b = 13 THEN
  38.             o$ = o$ + b$
  39.             ELSE y = y + 1
  40.         END IF
  41.     LOOP
  42. FINISH:
  43.     PRINT #2, o$
  44.     CLOSE
  45.     time2 = TIMER
  46. noold:
  47.     NAME infile$ AS oldfile$
  48.     NAME "temp" AS infile$
  49.     GOSUB TIME
  50.     PRINT "    Removed  :"; y
  51.     PRINT "Finish time  :"; newtime$
  52.     secs = time2 - time1
  53.     PRINT "Process rate :"; FIX(z / secs); "bps"
  54.     PRINT "Process time :"; CINT(secs); "secs."
  55.     END
  56. '*************************** GENERAL SUBROUTINES ******************************
  57. TIME:
  58.     intime$ = TIME$                                     'current time changed
  59.          hour$ = MID$(intime$, 1, 2)                     'to newtime$
  60.          min$ = MID$(intime$, 4, 2)
  61.          sec$ = MID$(intime$, 7, 2)
  62.          hour = VAL(hour$)
  63.              IF hour < 12 THEN ampm$ = "am" ELSE ampm$ = "pm"
  64.              IF hour > 12 THEN hour = hour - 12
  65.          hour$ = STR$(hour)
  66.     newtime$ = hour$ + ":" + min$ + ":" + sec$ + " " + ampm$
  67.     RETURN
  68. '****************************** HELP AND ERROR ROUTINES ***********************
  69. help:
  70.     PRINT " "
  71.     PRINT "CLEANER cleans non - ASCII, upper ASCII and NULL characters from a file."
  72.     PRINT "(c) 1990 David A. Wesson"
  73.     PRINT " "
  74.     PRINT "Syntax: CLEANER  [d:]filename.ext   "
  75.     PRINT ""
  76.     PRINT "  NOTE: Backup called filename.OLD will be made."
  77.     END
  78. nofind:
  79.     PRINT "ERROR: No file by that name found."
  80.     GOTO help
  81. filename:                                       'splits infile$ into
  82.         period = INSTR(infile$, ".")              'file$ and ext$
  83.         IF period = 0 THEN
  84.             file$ = UCASE$(infile$)
  85.             ext$ = ""
  86.         ELSE
  87.             file$ = UCASE$(LEFT$(infile$, period - 1))
  88.             ext$ = UCASE$(MID$(infile$, period + 1))
  89.         END IF
  90.         RETURN
  91.  
  92. FUNCTION exists (search$)
  93.      savefile$ = search$
  94.      inregs.ax = &H4E00
  95.      inregs.cx = 1     '3 for hidden
  96.      search$ = search$ + CHR$(0)
  97.      inregs.dx = SADD(search$)
  98.      inregs.ds = -1
  99.      CALL INTERRUPTX(&H21, inregs, outregs)
  100.      IF (outregs.flags AND 1) = 1 THEN
  101.             exists = NO
  102.      ELSE
  103.             exists = YES
  104.      END IF
  105.      search$ = savefile$
  106. END FUNCTION
  107.  
  108.